﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;

using System.Linq;
using System.Linq.Expressions;
using ProjectBase.Core;

namespace $safeprojectname$
{
    public static partial class Ext
    {
        /// <summary>new StringLengthRule</summary>
        public static StringLengthRule<TItem> For<TItem>(this RuleCollection<TItem> ruleList, Expression<Func<TItem, string>> expression)
            where TItem : class
        {
            var rule = new StringLengthRule<TItem>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new ValueTypeRule</summary>
        public static ValueTypeRule<TItem, TValue> For<TItem, TValue>(this RuleCollection<TItem> ruleList, Expression<Func<TItem, TValue>> expression)
            where TItem : class
            where TValue : struct, IComparable<TValue>
        {
            var rule = new ValueTypeRule<TItem, TValue>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new ValueTypeNullableRule</summary>
        public static ValueTypeNullableRule<TItem, TValue> For<TItem, TValue>(this RuleCollection<TItem> ruleList, Expression<Func<TItem, TValue?>> expression)
            where TItem : class
            where TValue : struct, IComparable<TValue>
        {
            var rule = new ValueTypeNullableRule<TItem, TValue>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new ReferenceRule</summary>
        public static ReferenceRule<TItem, TReference> Require<TItem, TReference>(this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, TReference>> expression)
            where TItem : class
            where TReference : class
        {
            var rule = new ReferenceRule<TItem, TReference>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new ReferenceHasRequiredSettingsRule</summary>
        public static ReferenceHasRequiredSettingsRule<TItem, TReference> AssureThatReference<TItem, TReference>(
            this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, TReference>> expression)
            where TItem : class
            where TReference : class
        {
            var rule = new ReferenceHasRequiredSettingsRule<TItem, TReference>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new UniqueRule</summary>
        public static UniqueRule<TItem> IsUnique<TItem>(this RuleCollection<TItem> ruleList, Func<TItem, IEnumerable<TItem>> expression, params string[] uniqueProperties)
            where TItem : class, IPersistentObject
        {
            var rule = new UniqueRule<TItem>(expression, uniqueProperties);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new UniqueCollectionItemRule</summary>
        public static UniqueCollectionItemRule<TItem, int, TValue> AssureThatCollection<TItem, TValue>(
            this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, IEnumerable<TValue>>> expression)
            where TItem : class, IPersistentObjectWithTypedId<int>
        {
            var rule = new UniqueCollectionItemRule<TItem, int, TValue>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new CollectionItemsHaveRequiredSettingsRule</summary>
        public static CollectionItemsHaveRequiredSettingsRule<TItem, int, TValue> AssureThatEachItem<TItem, TValue>(
            this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, IEnumerable<TValue>>> expression)
            where TItem : class, IPersistentObjectWithTypedId<int>
        {
            var rule = new CollectionItemsHaveRequiredSettingsRule<TItem, int, TValue>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new DelegateRule</summary>
        public static DelegateRule<TItem> Assure<TItem>(this RuleCollection<TItem> ruleList
            , DelegateRule<TItem>.Assure expression)
            where TItem : class
        {
            var rule = new DelegateRule<TItem>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new EnumerableRule</summary>
        public static NotEmptyEnumerableRule<TItem, TValue> RequireNotEmpty<TItem, TValue>(this RuleCollection<TItem> ruleList, Expression<Func<TItem, IEnumerable<TValue>>> expression)
            where TItem : class
        {
            var rule = new NotEmptyEnumerableRule<TItem, TValue>(expression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new RegularExpressionRule</summary>
        public static RegularExpressionRule<TItem> MatchExpression<TItem>(this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, string>> expression
            , string regularExpression)
            where TItem : class
        {
            var rule = new RegularExpressionRule<TItem>(expression, regularExpression);
            ruleList.Add(rule);
            return rule;
        }

        /// <summary>new RegularExpressionRule matching email syntax</summary>
        public static RegularExpressionRule<TItem> MatchEmail<TItem>(this RuleCollection<TItem> ruleList
            , Expression<Func<TItem, string>> expression)
            where TItem : class
        {
            var rule = new RegularExpressionRule<TItem>(expression, Templates.PatternEmailStrict);
            ruleList.Add(rule);
            return rule;
        }
    }
}